#include <buola/chart/plots/cerrorplot.h>

#include <buola/image/cgc.h>
#include <buola/chart/cxychart.h>
#include <buola/chart/cxaxis.h>
#include <buola/chart/cyaxis.h>

namespace buola { namespace chart {

CErrorPlot::CErrorPlot()
{
}

CErrorPlot::~CErrorPlot()
{
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
////////////////////////// Interface //////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

void CErrorPlot::SetMinSeries(PSeries pSeries)
{
    mMinSeries=pSeries;
}

void CErrorPlot::SetMaxSeries(PSeries pSeries)
{
    mMaxSeries=pSeries;
}

double CErrorPlot::GetMinY()
{
    return min(mSeries->mMin.y,min(mMinSeries->mMin.y,mMaxSeries->mMin.y));
}

double CErrorPlot::GetMinPosY()
{
    return min(mSeries->mMinPos.y,min(mMinSeries->mMinPos.y,mMaxSeries->mMinPos.y));
}

double CErrorPlot::GetMaxY()
{
    return max(mSeries->mMax.y,max(mMinSeries->mMax.y,mMaxSeries->mMax.y));
}

void CErrorPlot::DrawComplements(CXYChartContext &pC)
{
    pC.mGC->SetSource(mLineColor);
    pC.mGC->SetLineWidth(mLineWidth);
            
    for(int j=0;j<mPoints.size();j++)
    {
        CPoint_d lUp(mPoints[j].mPoint.x,pC.mYAxis->Map(mMaxSeries->GetY(j)));
        CPoint_d lDown(mPoints[j].mPoint.x,pC.mYAxis->Map(mMinSeries->GetY(j)));
        pC.mGC->Path().MoveTo(lUp);
        pC.mGC->Path().LineTo(lDown);
        pC.mGC->Path().MoveTo(CPoint_d(lUp.x-2,lUp.y));
        pC.mGC->Path().LineTo(CPoint_d(lUp.x+2,lUp.y));
        pC.mGC->Path().MoveTo(CPoint_d(lDown.x-2,lDown.y));
        pC.mGC->Path().LineTo(CPoint_d(lDown.x+2,lDown.y));
        pC.mGC->StrokePath();
    }
}

/*namespace chart*/ } /*namespace buola*/ }
